#include <iostream>
#include <thread>
#include <vector>
#include <mutex>

using namespace std;

class AT
{
    public:

    void myprint1()
    {
        for(int i=0;i<10000;++i)
        {
        cout << "myprint1-"<<i << endl;
        my_mutex.lock();
        commvec.push_back(i);
        my_mutex.unlock();
        }        
    }

      void myprint2()
    {
        for(int i=0;i<10000;++i)
        {
        cout << "myprint2-"<<i << endl;
        my_mutex.lock();
        commvec.push_back(i);
        my_mutex.unlock();
        }
    }
    private:
    vector<int> commvec;//公共变量
    mutex my_mutex;
};

int main()
{
    AT at;
   thread th1(&AT::myprint1,&at);
   thread th2(&AT::myprint2,&at);
    th1.join();
    th2.join();
    
    /*
    vector<thread> mythreads;
    for(int i=0;i<10;i++)//创建执行线程
    {
        mythreads.push_back(thread(myprint,i));
    }
   for(auto iter= mythreads.begin();iter!=mythreads.end();iter++) 
   {
        iter->join();
   }
*/

    cout<< "1主线程:" << endl;
    cout<< "2主线程:" << endl;
    cout<< "3主线程:" << endl;
    return 0;
}
